package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.FacilityInfoService;
import com.atguigu.lease.model.bean.FacilityInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.model.result.Response;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name="配套管理模块")
@RestController
@RequestMapping("/admin/facility")
public class FacilityInfoController {
    @Autowired
    FacilityInfoService facilityInfoService;
    @Operation(summary = "3、根据id删除配套")
    @DeleteMapping("deleteById")
    public Response deleteById(
            @Parameter(description = "配套id" ,required = true , in = ParameterIn.QUERY)
            @RequestParam("id") Long id){
        facilityInfoService.removeById(id);
        return Response.ok(null);
    }


    @Operation(summary = "2、新增或修改配套")
    @PostMapping("saveOrUpdate")
    public Response saveOrUpdate(@RequestBody FacilityInfo facilityInfo) {
        facilityInfoService.saveOrUpdate(facilityInfo);
        return Response.ok(null);
    }
    @Operation(summary = "1、根据type类型查询公寓或房间的配套列表")
    @GetMapping("list")
    public Response<List<FacilityInfo>> list(ItemType type) {
        List<FacilityInfo> facilityInfos = facilityInfoService.list(Wrappers.lambdaQuery(FacilityInfo.class)
                .eq(type != null, FacilityInfo::getType, type)
        );
        return Response.ok(facilityInfos);
    }
}
